<!-- 表单弹窗 -->
<form id="auth-form" lay-filter="auth-form" class="layui-form layui-form-pane" style="padding: 15px 15px 0px 15px">
    <input name="pid" type="hidden"/>
    <input name="parentAuth" type="hidden" id="parentAuth"/>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="layui-icon required">&#xe642;</i>父级权限</label>
        <div class="layui-input-block">
            <input name="parentAuthText" type="text" placeholder="请选择父级权限" class="layui-input" maxlength="20"
                   lay-verify="required" required id="parentAuthText"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="layui-icon required">&#xe642;</i>权限类型</label>
        <div class="layui-input-block">
            <select name="authType">
                <option value="">请选择</option>
                <option th:each="dict,authStat:${authTypeList}" th:value="${dict.dataCode}" th:text="${dict.dataText}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="layui-icon required">&#xe642;</i>显示名称</label>
        <div class="layui-input-block">
            <input name="displayName" placeholder="请输入显示名称" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="layui-icon required">&#xe642;</i>权限地址</label>
        <div class="layui-input-block">
        	<input name="directUrl" placeholder="请输入权限地址" type="text" class="layui-input" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限标识</label>
        <div class="layui-input-block">
        	<input name="authPerms" placeholder="请输入权限标识" type="text" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">权限描述</label>
        <div class="layui-input-block">
            <textarea name="authDescribe" placeholder="请输入描述内容" class="layui-textarea" style="border: 0px;border-left: 1px solid #e6e6e6;"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示排序</label>
        <div class="layui-input-block">
            <input name="sortOrder" placeholder="请输入显示排序" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog"><i class="layui-icon">&#x1006;</i> 取消</button>
        <button class="layui-btn" lay-filter="auth-form-submit" lay-submit><i class="layui-icon">&#xe605;</i> 保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'jquery', 'sadmin', 'tableSelect', 'form'], function () {
        var $ = layui.$ //重点处
        var layer = layui.layer;
        var sadmin = layui.sadmin;
        var tableSelect = layui.tableSelect;
        var form = layui.form;

        form.render('radio');
        form.render('select');

        var url = 'system/auth/save';
        // 回显user数据
        var auth = sadmin.getTempData('system_auth');
        if (auth) {
            $('input[name="authName"]').attr('readonly', 'readonly');
            url = 'system/auth/save';
            form.val('auth-form', auth);
        }

        tableSelect.render({
            elem: '#parentAuthText',
            checkedKey: 'pid',
            table: {
                url: 'system/auth/pageList',
                cols: [
                    [
                    {type: 'radio'},
                    {field: 'displayName', sort: true, title: '显示名称'},
                    {field: 'authTypeText', width: 100, title: '权限类型'},
                    {field: 'directUrl', title: '资源地址'}
                    ]
                ]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.displayName)
                    $('input[name="parentAuth"]').val(item.pid);
                })
                elem.val(NEWJSON.join(","))
            }
        })

        // 表单提交事件
        form.on('submit(auth-form-submit)', function (data) {
            layer.load(2);
            $.post(url, data.field, function (result) {
                layer.closeAll('loading');
                layer.msg(result.msg);
                sadmin.finishPopupCenter();
            });
            return false;
        });
    });
</script>